package com.iceland.server.server.proxy;

import com.iceland.common.rpc.RpcMessageManager;
import com.iceland.server.server.Server;
import com.iceland.server.server.cmd.ChannelPool;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * 处理类似浏览器发出的请求
 */
public class ProxyServer extends Server {

    RpcMessageManager rpcMessageManager;

    public RpcMessageManager getRpcMessageManager() {
        return rpcMessageManager;
    }

    public void setRpcMessageManager(RpcMessageManager rpcMessageManager) {
        this.rpcMessageManager = rpcMessageManager;
    }

    ChannelPool channelPool=new ChannelPool();

    public ChannelPool getChannelPool() {
        return channelPool;
    }

    public ProxyServer() {
        super(1,2, NioServerSocketChannel.class);
    }
    public ProxyServer(int bossThreadCount, int workThreadCount, Class channelClass) {
        super(bossThreadCount, workThreadCount, channelClass);
    }

    @Override
    protected void preStart(ServerBootstrap sb) {
        sb.childHandler(new ChannelInitializer<SocketChannel>() { // (4)
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addFirst(new ProxyHandler());
            }
        });
    }

    @Override
    protected void afterStart() {

    }
}
